package com.zjgk.hotel.config;



import com.zjgk.hotel.handler.AdminLoginInterceptor;
import com.zjgk.hotel.handler.UserLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {
    @Autowired
    private UserLoginInterceptor userLoginInterceptor;
    @Autowired
    private AdminLoginInterceptor adminLoginInterceptor;


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userLoginInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/user/wx/login")
                .excludePathPatterns("/room/content")
                .excludePathPatterns("/admin/**");
        registry.addInterceptor(adminLoginInterceptor).addPathPatterns("/admin")
                .excludePathPatterns("/admin/login");
    }
}
